<#-- 
	Java Entity Class (template) Code generation template for Hibernate
	by   : Young Suk Ahn (Altenia Corp.)
	modif: 2011/05/14
-->
<#include "hbm2java_common.ftl">

<#macro default_val type>
<#if type?upper_case=="LONG" || type?upper_case=="INT" || type?upper_case=="INTEGER" || type?upper_case=="SHORT" || type?upper_case=="TINYINT" || type?upper_case=="SMALLINT" || type?upper_case=="SHORTINT">0<#elseif type?upper_case=="FLOAT" || type?upper_case=="DOUBLE" || type?upper_case=="DECIMAL">0.0<#elseif type?upper_case=="CHAR" || type?upper_case=="VARCHAR" || type?upper_case=="STRING" || type?upper_case=="TEXT" || type?upper_case=="DATE" || type?upper_case=="TIMESTAMP">null<#elseif type?upper_case=="BINARY" || type?upper_case=="BIN">null<#else>null</#if></#macro>

<#macro process_column xmlElement>
<#assign col_name = xmlElement.@name >
<#assign col_type = (xmlElement.@type[0])!"TYPE_MISSING" >
<#if col_type == "TYPE_MISSING" ><#assign col_type = (xmlElement.@class[0])!"TYPE_MISSING" ></#if>
<#assign col_primaryKey = (xmlElement.@primaryKey[0])!"" >
<#assign col_required = (xmlElement.@required[0])!"" >
<#assign col_size = (xmlElement.@length[0])!"" >
<#assign col_description = (xmlElement.meta[0])!"" >
<#if col_primaryKey != "" ><#assign attr_primaryKey = ", isPrimaryKey=${col_primaryKey}" ><#else><#assign attr_primaryKey = "" ></#if>
<#if col_required != "" ><#assign attr_required = ", isRequired=${col_required}" ><#else><#assign attr_required = "" ></#if>
<#if col_size != "" ><#assign attr_size = ", size=\"${col_size}\"" ><#else><#assign attr_size = "" ></#if>
	protected <@print_java_type type=col_type /> ${col_name} = <@default_val type=col_type />; /* ${col_description} <#if col_size != "" >(length:${col_size})</#if> */ 
</#macro>
/**
 * Generated by ddl2java_entity_class.ftl
 */ 
<#assign classes = .node["hibernate-mapping/class"] >
<#list classes as class >
	<#assign class_name = class.@name>
	<#assign table_name = class.@table>
	<#assign namespace  = (class.@namespace[0])!"">
<#if namespace != "" >package ${namespace};<#else>package <@print_java_packagename fqName=class_name />;</#if>

import java.util.Date;

/**
 * Entity Class ${class_name}
 * Generated by hbm2java_entity_class.ftl (v20110614)
 *
 */
public class <@print_java_classname fqName=class_name /> {
<#list class.property as column >
<@process_column xmlElement=column />
</#list>

<#-- Generets for many-to-one mapping -->
	// Many to one mappings:
<#assign properties = .node["hibernate-mapping/class/many-to-one"] >
<#list properties as column >
<@process_column xmlElement=column />
</#list>

<#list class.property as column >
	<#assign col_name = column.@name >
	<#assign col_type = (column.@type)!"TYPE_MISSING" >
	public <@print_java_type type=col_type /> get${col_name?cap_first}() {
		return ${col_name};
	}
	public void set${col_name?cap_first}(<@print_java_type type=col_type /> ${col_name}) {
		this.${col_name} = ${col_name};
	}
</#list>


<#-- Generets for many-to-one mapping -->
	// Many-to-one mappings:
<#assign properties = .node["hibernate-mapping/class/many-to-one"] >
<#list properties as column >
	<#assign col_name = column.@name >
	<#assign col_type = (column.@class[0])!"TYPE_MISSING" >
	public <@print_java_type type=col_type /> get${col_name?cap_first}() {
		return ${col_name};
	}
	public void set${col_name?cap_first}(<@print_java_type type=col_type /> ${col_name}) {
		this.${col_name} = ${col_name};
	}
</#list>
}
</#list>
